package cn.zf;

import java.util.Arrays;

public class Mst2 {
    public static void main(String[] args) {
        String[] str=new String[]{"age", "eat", "tea", "tan","ate", "nat", "bat", "book", "bkoo"};
        for (int n = 0; n < str.length; n++) {
            String t = str[n];
            if ("-".equals(t)) continue;
            for (int i = n + 1; i < str.length; i++) {
                if (isOk(t, str[i])) {
                    str[n] += "-" + str[i];
                    str[i] = "";
                }
            }
        }

    }
    public static boolean isOk(String a,String b){
         boolean f=false;
        if(a.length()==b.length()){
         var a1= a.toCharArray();
            Arrays.sort(a1);
            var a2=b.toCharArray();
            Arrays.sort(a2);
            f = new String(a1).equalsIgnoreCase(new String(a2));
     }

        return f;
    }
}
